package com.ego.item.service.impl;

import com.ego.item.mapper.CategoryMapper;
import com.ego.item.pojo.Category;
import com.ego.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class CategoryServiceImpl implements CategoryService{
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public List<Category> findListByPid(Long pid) {
        Category category = new Category();
        category.setParentId(pid);
        List<Category> result = categoryMapper.select(category);
        return result;
    }

    @Transactional
    @Override
    public void save(Category category) {
        categoryMapper.insert(category);
    }
    @Transactional
    @Override
    public void updateNameById(Long id, String name) {
        categoryMapper.updateNameById(id,name);
    }
    @Transactional
    @Override
    public void deleteById(Long id) {
        categoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Category> findListByBid(Long bid) {
        return categoryMapper.findListByBid(bid);
    }

    @Override
    public List<Category> findListByCids(List<Long> cids) {
        return categoryMapper.selectByIdList(cids);
    }
}
